import React from "react";
import Footer from "../../components/common/footer/index";
import { Head, Catalog } from "./style";
import { connect } from "react-redux";
import { getUserInfo } from "../../store/actions";

// const jf = require("../../assets/img_jf.png");
const tj = require("../../assets/img_tj.png");
const fk = require("../../assets/img_fk.png");
class Index extends React.PureComponent {
  componentDidMount() {
    // this.props.login();
    
    if (window.location.href.indexOf('openid')>-1 && this.props.location.search.split('=')[1]) {
      this.props.login(this.props.location.search.split('=')[1]);
    } else {
      // if (!sessionStorage.getItem("userInfo")) {
      //   window.location.href = 'http://www.yermn.com/api/auth/login?url=http://www.yermn.com/#/me'
      // }
    }
  }
  goHelp(){
    this.props.history.push("/help/");
  }
  goShare(){
    this.props.history.push("/invite/");
  }
  render() {
    return (
      <div>
        {this.props.userInfo ? (
          <Head>
            <div className="bg" />
            <div className="mp">
              <img src={this.props.userInfo.avatar} alt="" />
              <p>
                {this.props.userInfo.nickname}
                <br />
                {this.props.userInfo.phone}
              </p>
            </div>
          </Head>
        ) : (
          ""
        )}
        <Catalog>
          {/* <li>
            <span>{this.props.userInfo.integral}</span>
            <img src={jf} alt="" />
            我的积分
          </li> */}
          <li onClick={this.goShare.bind(this)}>
            <img src={tj} alt="" />
            推荐有奖
          </li>
          <li onClick={this.goHelp.bind(this)}>
            <img src={fk} alt="" />
            反馈与帮助
          </li>
        </Catalog>
        <Footer atthis="me" />
      </div>
    );
  }
}
const mapStateToProps = state => ({
  userInfo: state.userInfo
});
const mapDispatchToProps = dispatch => ({
  login: (openId) => dispatch(getUserInfo(openId))
});
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Index);
